Imports System.ComponentModel
Imports System.Globalization


Public Class dataTypeConverter
    Inherits TypeConverter

    ' Overrides the CanConvertFrom method of TypeConverter.
    ' The ITypeDescriptorContext interface provides the context for the
    ' conversion. Typically, this interface is used at design time to 
    ' provide information about the design-time container.
    Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
        If sourceType Is GetType(String) Or sourceType Is GetType(Integer) Then
            Return True
        End If
        ' Return MyBase.CanConvertFrom(context, sourceType)
    End Function

    ' convierte de cadena a dataType
    ' Overrides the ConvertFrom method of TypeConverter.
    Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
        If TypeOf value Is String Then
            'Dim v As String() = CStr(value).Split(New Char() {","c})
            'Return New Point(Integer.Parse(v(0)), Integer.Parse(v(1)))
            Select Case value
                Case "entero"
                    Return 130

                Case Else

                    Return 0 'CType(value, dataTypes.dataType)
            End Select
        End If
        'Return MyBase.ConvertFrom(context, culture, value)
        Return 0
    End Function

    ' convierte de dataType a cadena
    ' Overrides the ConvertTo method of TypeConverter.
    Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
        If value Is Nothing Then
        Else
            If destinationType Is GetType(String) Then

                Select Case value
                    Case "130"
                        Return "entero"
                End Select
                ' Return CType(value, Point).X & "," & CType(value, Point).Y
                ' Return "jkjkjk"
            End If
            Return MyBase.ConvertTo(context, culture, value, destinationType)
        End If

    End Function

    ' Indicates this type converter provides a list of standard values.
    Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
        Return True
    End Function 'GetStandardValuesSupported



    Private values As ArrayList

    ' Returns a StandardValuesCollection of standard value objects.
    Public Overloads Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection
        ' Passes the local integer array.

        values = New ArrayList(New String() {"entero", "doble", "fecha", "fechaLarga", "cadena", "enteroCorto", "enteroLargo", "decimalx", "booleano", "blob", "varchar", "texto", "guid"})
        Dim svc As New StandardValuesCollection(values)
        Return svc
    End Function 'GetStandardValues

End Class


